package leetcode.L500;

import java.util.LinkedList;
import java.util.Queue;

public class EX130 {
    //bfs
/*    public static void main(String[] args) {
        char[][] board = {};
        int n = board.length;
        int m = board[0].length;
        Queue<int[]> queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            if(board[i][0]=='O'){
                queue.offer(new int[]{i,0});
            }
            if(board[i][m-1]=='O'){
                queue.offer(new int[]{i,m-1});
            }
        }
        for (int i = 0; i < m ; i++) {
            if(board[0][i]=='O'){
                queue.offer(new int[]{0,i});
            }
            if(board[n-1][i]=='O'){
                queue.offer(new int[]{n-1,i});
            }
        }
        while (!queue.isEmpty()){
            int [] cell = queue.poll();
            int x = cell[0],y = cell[1];
            board[x][y]='A';
            int x1 = x-1,y1 = y; //左
            int x2 = x+1,y2 = y; //右
            int x3 = x,y3 = y-1; //上
            int x4 = x,y4 = y+1; //下


            if(x1>0&&board[x1][y1]=='O'){
                queue.offer(new int[]{x1,y1});
            }
            if(x2<n&&board[x2][y2]=='O'){
                queue.offer(new int[]{x2,y2});
            }
            if(y3>0&&board[x3][y3]=='O'){
                queue.offer(new int[]{x3,y3});
            }
            if(y4<m&&board[x4][y4]=='O'){
                queue.offer(new int[]{x4,y4});
            }
        }
        for (int i = 0; i < n ; i++) {
            for (int j = 0; j < m ; j++) {
                if(board[i][j]=='A'){
                    board[i][j] = 'O';
                }
                else if(board[i][j]=='O'){
                    board[i][j]='X';
                }
            }
        }
    }*/


}
